#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys

reload(sys)
sys.setdefaultencoding('utf-8')

event_config = {}
with open('event_config.txt') as f:
    for i in f:
        t=i.strip().split('\001')
        if len(t)==3:
            eventid,cid,sid = map(str,t)
            event_config.setdefault(cid,{})
            event_config[cid][eventid]=sid

for i in sys.stdin:
    t=i.strip().split('\t',6)
    if len(t)==7:
        cid,sid,day,value,nasid,pv,ispay=t
        cid = str(cid)
        sid = str(sid)
        if cid in event_config:
            tmp = event_config[cid]
            value_list=value.strip().split('\001')
            actions={}
            for j in value_list:
                tmp2=j.strip().split(',',2)
                if len(tmp2)==3:
                    time,customize,query=tmp2
                    if customize and len(customize)>0 and str(customize) in tmp and sid in tmp[str(customize)]:
                        actions[time]=[1,customize]
                    if query and len(query)>0:
                        actions[time]=[0,query]
            
            query_flag=False
            query_tmp=''
            for k,v in sorted(actions.iteritems()):
                if v[0]==0:
                    query_flag=True
                    query_tmp=v[1]
                    continue
                if v[0]==1:
                    if query_flag:
                        print '\t'.join(map(str,[cid,sid,day,'1',v[1],query_tmp,nasid,pv,ispay]))
                